<template>
    <div class="wrap">
        <van-cell-group>
            <van-field v-model="loginNo" label="登录帐号" placeholder="请输入登录帐号" />
        </van-cell-group>
        <van-cell-group>
            <van-field type="password" v-model="oldPassword" label="旧密码" placeholder="请输入旧密码" />
        </van-cell-group>
        <van-cell-group>
            <van-field type="password" v-model="newPassword" label="新密码" placeholder="请输入新密码" />
        </van-cell-group>
        <van-cell-group>
            <van-field type="password" v-model="confirmPassword" label="新密码" placeholder="请再次输入新密码" />
        </van-cell-group>
        <div class="sure" @click="submit">确定</div>
    </div>
</template>

<script>
import Vue from 'vue';
import { Field } from 'vant';
import { editPassword } from "../../../api/user.js";

Vue.use(Field);
export default {
    data() {
        return {
            loginNo: "",
            oldPassword: "",
            newPassword: "",
            confirmPassword: ""
        };
    },
    created() {

    },
    mounted() {

    },
    methods: {
        submit() {
            if (!this.loginNo.trim()) {
                this.$toast({type: "danger", message: "帐号不能为空"})
                return
            }
            if (!this.oldPassword.trim()) {
                this.$toast({type: "danger", message: "旧密码不能为空"})
                return
            }
            if (!this.newPassword.trim()) {
                this.$toast({type: "danger", message: "新密码不能为空"})
                return
            }
            if (!this.confirmPassword.trim()) {
                this.$toast({type: "danger", message: "新密码不能为空"})
                return
            }
            if (this.confirmPassword.trim() !== this.newPassword.trim()) {
                this.$toast({type: "danger", message: "两次密码不一致"})
                return
            }
            editPassword({
                "loginNo": this.loginNo,
                "oldPass": this.oldPassword,
                "passwordNew1": this.newPassword,
                "passwordNew2": this.confirmPassword
            }).then(response=>{
                if(response.retCode=="200"){
                    this.$toast("修改成功")
                    this.$router.go(-1)
                }else{
                    this.$toast(response.retMsg);
                }
                
            });
        }
    }
};
</script>

<style scoped lang="less">
/deep/ .van-field .van-cell__title {
    max-width: 2rem;
}
/deep/ .van-cell {
    padding: 0.4rem;
}
/deep/ .van-cell span {
    font-size: 0.373333rem;
    color: #333;
    font-weight: bold;
}
.wrap {
    height: 100%;
    background: #F7F7F7;
}
.sure {
    height: 50px;
    background: #FF531A;
    color: #fff;
    width: 9.2rem;
    display: flex;
    justify-content: center;
    align-content: center;
    font-size: 0.48rem;
    margin: 0 auto;
    margin-top: 0.533333rem;
    border-radius: 0.64rem;
    align-items: center;
}
</style>
